using System;

// Windows Media Player
using WMPLib;

namespace Engine.Media
{
    public class MediaPlayer
    {
        private WindowsMediaPlayer player;

        // Constructor
        public MediaPlayer()
        {
            player = new WindowsMediaPlayer();
        }

        // Play a media file
        public void Load(String url)
        {
            // Clear playlist
            player.currentPlaylist.clear();

            // Load url
            player.URL = url;
        }

        // Add a media file
        public void Add(String url)
        {
            // Retrieve media
            IWMPMedia media = player.newMedia(url);

            // Add to playlist
            if (media != null)
            {
                player.currentPlaylist.appendItem(media);
            }
        }

        // Wrapper functions
        public void Play()
        {
            // Play
            player.controls.play();
        }

        public void Pause()
        {
            // Pause
            player.controls.pause();
        }

        public void Stop()
        {
            // Stop
            player.controls.stop();
        }

        public void Previous()
        {
            // Previous
            player.controls.previous();
        }

        public void Next()
        {
            // Next
            player.controls.next();
        }

        // Acessors
        public IWMPMedia Current
        {
            get { return player.currentMedia; }
        }

        public IWMPPlaylist Playlist
        {
            get { return player.currentPlaylist; }
        }

        public int Volume
        {
            get { return player.settings.volume; }
            set { player.settings.volume = value; }
        }
    }
}
